﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GatewayInspect.Common;
using System.Data.OracleClient;

namespace GatewayInspect.Modules
{
    public partial class PAInOutGateJLModule : BaseModule
    {
        public PAInOutGateJLModule()
        {
            InitializeComponent();
        }

        protected override void OnInitialize()
        {
            base.OnInitialize();
            foreach (ToolStripItem item in this.tsMain.Items)
            {
                if (item != tsBtnRefresh && item != tsBtnClose && item != toolStripSeparator3)
                {
                    item.Visible = false;
                }
            }
        }

        protected override void OnInit()
        {
            base.OnInit();
            dtpInEnd.Value = DateTime.Now;
            dtpInBegin.Value = DateTime.Now.AddDays(-1);
            dtpOutEnd.Value = DateTime.Now;
            dtpOutBegin.Value = DateTime.Now.AddDays(-1);
        }

        protected override void OnLoadModule()
        {
            base.OnLoadModule();
            if (checkBox1.Checked == true)
            {
                dtpInEnd.Value = DateTime.Now;
            }
            if (checkBox2.Checked == true)
            {
                dtpOutEnd.Value = DateTime.Now;
            }
            string strSql = "select CHEHAO,IN_DATE,OUT_DATE,CARDID,decode(IN_OUT_BS, '1','在场','2','离场') ZT,decode(ORGCODE, '11','平安停车场1','12','平安停车场2','13','平安停车场3') TCC from IN_OUT_GATE where (ORGCODE = '11' OR ORGCODE = '12' OR ORGCODE = '13')";
            if (!string.IsNullOrWhiteSpace(tbxTruckNo.Text))
            {
                strSql += " and CHEHAO like '%" + tbxTruckNo.Text + "%'";
            }
            if (chbInDate.Checked)
            {
                strSql += " and IN_DATE>=to_date('" + dtpInBegin.Value.ToString() + "','yyyy-mm-dd hh24:mi:ss') and IN_DATE<=to_date('" + dtpInEnd.Value.ToString() + "','yyyy-mm-dd hh24:mi:ss')";
            }
            if (chbOutDate.Checked)
            {
                strSql += " and OUT_DATE>=to_date('" + dtpOutBegin.Value.ToString() + "','yyyy-mm-dd hh24:mi:ss') and OUT_DATE<=to_date('" + dtpOutEnd.Value.ToString() + "','yyyy-mm-dd hh24:mi:ss')";
            }
            if (comboBox1.Text == "平安停车场1")
            {
                strSql += " and ORGCODE = '11'";
            }
            if (comboBox1.Text == "平安停车场2")
            {
                strSql += " and ORGCODE = '12'";
            }
            if (comboBox1.Text == "平安停车场3")
            {
                strSql += " and ORGCODE = '13'";
            }
            if (cbbZT.Text == "在场")
            {
                strSql += " and IN_OUT_BS = '1'";
            }
            else if (cbbZT.Text == "离场")
            {
                strSql += " and IN_OUT_BS = '2'";
            }
           
            strSql += " order by RECTIME desc";
            DataTable dt = DataAccess.ExecuteDataTable(strSql);

            this.cdgvInOutGate.AutoGenerateColumns = false;
            this.cdgvInOutGate.DataSource = dt;
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            OnLoadModule();
        }
    }
}
